package net.zjitc.logincheckcode.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author Administrator
 * @Date 2020/6/9 15:49
 **/
public class JDBCUtils {
    private static DataSource ds;
    static {
        /*读取配置文件
        * 2.初始化ds
        * */
        try{
            Properties pro=new Properties();
            /*传入参数 ：通过类加载器将文件转成流对象*/
            pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
            ds = DruidDataSourceFactory.createDataSource(pro);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    /**
     *
     * @return
     */
    public static DataSource getDataSource(){
        return ds;
    }
    public static Connection getConnction() throws SQLException{
        return ds.getConnection();
    }
}
